package a10;

import java.util.Random;

public class MasterMind {
	private String value = null;

	public MasterMind() {

	}

	public MasterMind(String value) {
		this.value = value;
	}

	public int getIndirectHits(String value) {
		int tmp = 0;
		for (int i = 1; i < 5; i++) {
			if (!this.value.subSequence(i - 1, i).equals(
					value.subSequence(i - 1, i))) {
				for (int j = 1; j < 5; j++) {
					if (this.value.subSequence(j - 1, j).equals(
							value.subSequence(i - 1, i))) {
						tmp++;
					}
				}
			}
		}
		return tmp;
	}

	public int getHits(String value) {
		int tmp = 0;
		for (int i = 1; i < 5; i++) {
			if (this.value.subSequence(i - 1, i).equals(
					value.subSequence(i - 1, i))) {
				tmp++;
			}
		}
		return tmp;
	}

	public void generate() {
		this.value = "";
		int[] tempValue = new int[5];
		boolean[] numberInUse = new boolean[10];
		Random random = new Random();

		for (int i = 1; i < tempValue.length; i++) {
			do {
				tempValue[i] = random.nextInt(10);
			} while (numberInUse[tempValue[i]] == true);
			numberInUse[tempValue[i]] = true;
			this.value += tempValue[i];
		}
		this.value = "1234";
		//System.out.println(this.value);
	}

	public String getSolution() {
		return value;
	}
}
